﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GMS.Client.Core;
using GMS.Client.Model;
using GMS.Client.Domain;
using GMS.Client.Utility;
using System.Timers;
using System.Configuration;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

namespace GMS.Client.ConsoleTest
{
    public class Program
    {
        public static Timer RunningTimer { get; set; }
        public static int RunningMinute { get; set; }

        public static void Main(string[] args)
        {
            var gameInfos = PrepareData();
            Console.WriteLine("将配置信息文件序列化成List...");
            gameInfos.AsParallel().ForAll(g =>
            {
                Game(g);
            });
           
            Console.Read();
        }

        private static List<GameInfo> PrepareData()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"\Config.xml");
            Console.WriteLine("读取配置信息文件...");
            var memoryStream = new System.IO.MemoryStream();
            xmlDocument.Save(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);

            var serializer = new XmlSerializer(typeof(List<GameInfo>));
            return (List<GameInfo>)serializer.Deserialize(memoryStream);
        }

        private static void Game(GameInfo gameInfo)
        {
            var iRun = new RunService(gameInfo);
            iRun.Start();
        }
    }
}
